#!/usr/bin/python
# -*- coding: utf-8 -*-
import re,os,sys,Tool,requests

#返回为数组
def text_getMiddle(origin,left,right):
    left=str(left.replace("#引号","\"").replace("#换行符","\\n")).replace("(","\(").replace(")","\)").replace("[","\[").replace("]","\]").replace("{","\{").replace("}","\}")
    right = str(right.replace( "#引号" , "\"" ).replace("#换行符","\\n")).replace("(","\(").replace(")","\)").replace("[","\[").replace("]","\]").replace("{","\{").replace("}","\}")

    middleList=re.findall( '%s.*?%s' %(left,right) , origin )
    #print(origin)
    #middleList = re.findall( 'name\":\".*?\",', origin )
    #print(middleList)
    for u,middle in enumerate(middleList):
        #middleList[u]=middle.replace(left,"").replace(right,"")
        middleList[ u ] = middle.strip(left).strip(right)
    #if len(middleList)==0:
        #print("取中间失败，找不到")
    return  middleList

def text_getMiddle2(origin,left,right):
    left=str(left.replace("#引号","\"").replace("#换行符","\\n")).replace("(","\(").replace(")","\)").replace("[","\[").replace("]","\]").replace("{","\{").replace("}","\}")
    right = str(right.replace( "#引号" , "\"" ).replace("#换行符","\\n")).replace("(","\(").replace(")","\)").replace("[","\[").replace("]","\]").replace("{","\{").replace("}","\}")

    middleList=re.findall( '%s.*?%s' %(left,right) , origin )
    return  middleList


def file_writeToTxt(path="",content="",mode="w"):
    if path is "":
        print("输出文件地址为空，异常")
        input()
        return 0
    f = open( path,mode )
    f.write( content )

def file_getCurrentFilePath():
    return sys.path[0]

def web_get(url,cookies):
    headers = {
        'Cookie': cookies ,
        'Content-Type': "application/x-www-form-urlencoded"
    }
    # 发送
    req = requests.session( )
    rs = req.get( url=url , headers=headers )
    return rs.text

def web_post(url,content,cookies):
    headers = {
        'Cookie': cookies ,
        'Content-Type': "application/x-www-form-urlencoded"
    }
    # 发送
    req = requests.session( )
    rs = req.post( url=url , data=content , headers=headers )
    return rs.text



if __name__ == '__main__':
    print(text_getMiddle("a1ba2ba3b\n11","a","b\n"))
    print(text_getMiddle("a(http://1.com)[http://1.com]","a(",")"))
    # f = open( "C:\\Users\\10241982\\PycharmProjects\\untitled\\aa.txt" , "a+" )  # 以追加的方式
    #
    # f.write( "test file" )

    # print( sys.path[0])  # 写完通过\n进行换行
    # os.system(r"cp " + Tool.file_getCurrentFilePath( ) + "\C2.txt  " + Tool.file_getCurrentFilePath( ) + "\scan_result\C2.txt" )
    print(text_replaceAll("I like color color car.","c*or","blue"))
    print(text_replaceAll("a(http://1.com)[http://1.com] ","a\(.*\)","blue"))